import java.io.File
import java.util.Scanner

import scala.collection.immutable.TreeMap
import scala.collection.{SortedMap, mutable}
import scala.io.Source

/**
  * Created by lenovo on 2017/4/16.
  */
object Chapter4 {

  def main(args: Array[String]): Unit = {

    val a = Map("car" -> 100000, "phone" -> 5000, "clothes" -> 1000)
    //    , "phone" -> 5000,"clothes" -> 1000}

    val b = for ((k, v) <- a) yield (k, 0.9 * v)
    println(b)


    var in = new Scanner(new File("G:\\opt\\shell.sh"))
    val map = new mutable.HashMap[String, Int]
    while (in.hasNext) {
      val c = in.next();
      val token = c.split("\\s+");

      for (key <- token) {
        map(key) = map.getOrElse(key, 0) + 1

      }
    }
    println(map);

    val source = Source.fromFile("G:\\opt\\shell.sh").mkString;
    val token = source.split("\\s+");
    val map2 = new mutable.HashMap[String, Int]
    for (key <- token) {
      map2(key) = map2.getOrElse(key, 0) + 1
    }
    println(map2);
    var map3 = new mutable.HashMap[String, Int]
    for (key <- token) {
      map3(key) = map3.getOrElse(key, 0) + 1
    }
    println(map3);
    //    var map4 = new SortedMap[String,Int]()
    //    for(key <- token){
    //      map4 += key -> (map4.getOrElse(key , 0 )+1)
    //    }
    //    println(map4);
    var map4 = new TreeMap[String, Int]()
    for (key <- token) {
      map4 += key -> (map4.getOrElse(key, 0) + 1)
    }
    println(map4);


    println("Hello".zip("world"))
  }

}
